package com.hy.mydesktop.shared.persistence.domain.gxt;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.IndexColumn;

import net.sf.gilead.annotations.ServerOnly;

import com.hy.mydesktop.client.component.type.ComponentControllerEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.LibConstants;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.MetaDataConstants;

/**
 * 
 * 
 * <ul>
 * <li>开发作者：花宏宇</li>
 * <li>设计日期：2011-9-12；时间：下午05:33:48</li>
 * <li>类型名称：GxtComponentControllerMetaNodeModel</li>
 * <li>设计目的：用于存储BaseController的配置信息；GxtComponentControllerMetaModel中的元素</li>
 * <li>类属性及方法说明：<br> 
 * getRegisterEventTypes() :  用于存储以GxtAppEventType的Set<br>
 * getLeftValue():  存储GxtComponentControllerMetaNodeModel在线性表的左值<br>
 * getRightValue():  存储GxtComponentControllerMetaNodeModel在线性表的右值<br>
 * getControllerMetaNodeModelId():  获取GxtComponentControllerMetaNodeModel的Id<br>
 * getGxtComponentMetaNodeModel():  获取GxtComponentControllerMetaNodeModel的Id<br>
 * getComponentControllerEnum() : 存储控制器的类型，即ComponentControllerEnum<br>
 * getComponentControllerEnumIndex() : 存储控制器的类型的索引序号，即ComponentControllerEnum对应的序号<br>
 * GxtComponentMetaModel迟绑定：gxtMetaModelTypeEnum用于判断GxtComponentMetaModel是属于BaseModel还是
 * 其子类TreeModel</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@Entity
@Table(name="t_gxt_Component_Controller_MetaNodeModel")
public class GxtComponentControllerMetaNodeModel extends MyBaseModel{// extends GxtComponentMetaNodeModel{
	
	//registereventtypes
	//gxtcomponentmetanodemodel
	/**
	 * <ul>
	 * <li>开发作者：花宏宇</li>
	 * <li>设计日期：2010-8-29；时间：下午02:28:48</li>
	 * <li>字段类型：long；字段名称：serialVersionUID</li>
	 * <li>设计目的：</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 */
	private static final long serialVersionUID = 6357423258767982589L;
	//private int leftValue;
	//private int rightValue;
	//private int parentLeftValue;
	//private int leftValue;
	//private int rightValue;
	/*public int getLeftValue() {
		return leftValue;
	}

	public void setLeftValue(int leftValue) {
		this.leftValue = leftValue;
	}

	public int getRightValue() {
		return rightValue;
	}

	public void setRightValue(int rightValue) {
		this.rightValue = rightValue;
	}*/
	/*public int getParentLeftValue() {
		return parentLeftValue;
	}

	public void setParentLeftValue(int parentLeftValue) {
		this.parentLeftValue = parentLeftValue;
	}*/

	/*@Id
	public String getId() {
		return super.get("id");
	}

	public void setId(String id) {
		super.set("id", id);
	}*/
	
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：获取将要创建的控件的元数据</li>
	 * <li>方法作者：花宏宇</li>
	 * <li>编写日期：2010-9-19；时间：下午上午11:35:35</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @return
	 */
	//@ServerOnly
	//@Transient
	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	public GxtComponentMetaNodeModel getGxtComponentMetaNodeModel() {
//		return super.get("gxtComponentMetaNodeModel");
		return super.get(MetaDataConstants.GXT_COMPONENT__METANODEMODEL);
	}

	public void setGxtComponentMetaNodeModel(GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {
		super.set(MetaDataConstants.GXT_COMPONENT__METANODEMODEL, gxtComponentMetaNodeModel);
	}
	
	
	public String getControllerMetaNodeModelId() {
		return super.get(MetaDataConstants.COMPONENT_CONTROLLER_ID);
//		return controllerMetaModelId;
	}

	public void setControllerMetaNodeModelId(String controllerMetaNodeModelId) {
		super.set(MetaDataConstants.COMPONENT_CONTROLLER_ID, controllerMetaNodeModelId);
//		this.controllerMetaModelId = controllerMetaModelId;
	}
	
	//@Transient
//	@ManyToMany(cascade={CascadeType.DETACH,CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH},fetch=FetchType.EAGER)
	@ManyToMany(cascade={CascadeType.ALL},fetch=FetchType.EAGER)
//	@JoinColumn(name="GxtComponentMetaNodeModel_identifier")

	public Set<GxtAppEventType> getRegisterEventTypes() {
//		return super.get("registerEventTypes");
		return super.get(MetaDataConstants.APP_EVENT_TYPES);
	}

	public void setRegisterEventTypes(Set<GxtAppEventType> registerEventTypes) {
		super.set(MetaDataConstants.APP_EVENT_TYPES, registerEventTypes);
	}
	
	//@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	/*@Transient
	public Set<GxtComponentControllerMetaNodePorperty> getControllerProperties() {
		return super.get("controllerProperties");
	}

	public void setControllerProperties(Set<GxtComponentControllerMetaNodePorperty> controllerProperties) {
		super.set("controllerProperties", controllerProperties);
	}*/
	
	@Column(nullable=true)
	public Integer getLeftValue() {
		return super.get(MetaDataConstants.LEFT_VALUE,0);
	}

	public void setLeftValue(Integer leftValue) {
		super.set(MetaDataConstants.LEFT_VALUE, leftValue);
	}
	@Column(nullable=true)

	public Integer getRightValue() {
		return super.get(MetaDataConstants.RIGHT_VALUE,0);
	}

	public void setRightValue(Integer rightValue) {
		super.set(MetaDataConstants.RIGHT_VALUE, rightValue);
	}
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：获取将要创建的控件控制器Controller的真实类型</li>
	 * <li>方法作者：花宏宇</li>
	 * <li>编写日期：2010-9-19；时间：下午上午11:35:35</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @return
	 */
	@Transient
	//@Enumerated(EnumType.STRING)
	//@Column(nullable=true)
	@ServerOnly

	public ComponentControllerEnum getComponentControllerEnum ( )
	{
		return this.get (MetaDataConstants.COMPONENT_CONTROLLER_MODEL_TYPE ) ;
	}
	public void setComponentControllerEnum (ComponentControllerEnum componentControllerEnum )
	{
		this.set (MetaDataConstants.COMPONENT_CONTROLLER_MODEL_TYPE,  componentControllerEnum) ;
		this.setComponentControllerEnumName(componentControllerEnum.toString());
	}
	@Column(nullable=true)
	public String getComponentControllerEnumName ( )
	{
		return this.get (MetaDataConstants.COMPONENT_CONTROLLER_MODEL_TYPE_NAME ) ;
	}
	public void setComponentControllerEnumName (String componentControllerEnumName )
	{
		this.set (MetaDataConstants.COMPONENT_CONTROLLER_MODEL_TYPE_NAME,  componentControllerEnumName) ;
	}
	
	public int getComponentControllerEnumIndex ( )
	{
		return this.get (MetaDataConstants.COMPONENT_CONTROLLER_MODEL_TYPE_INDEX ,0) ;
	}
	public void setComponentControllerEnumIndex (int componentControllerEnumIndex )
	{
		this.set (MetaDataConstants.COMPONENT_CONTROLLER_MODEL_TYPE_INDEX,  componentControllerEnumIndex) ;
	}
			
	
	

	
	
	
	
	/**
	 * 构造函数
	 */
	public GxtComponentControllerMetaNodeModel ( )
	{
		super ( ) ;
		//this.set (LibConstants.COMPONENT_CONTROLLER_MODEL_TYPE.name().toLowerCase(),  ComponentControllerEnum.NONE_CONTROLLER_MODEL) ;

		
	}

	/**
	 * 构造函数
	 */
	public GxtComponentControllerMetaNodeModel (Map < String , Object > properties )
	{
		super (
				properties ) ;
		this.setLeftValue(1);
		this.setRightValue(2);
		
	}

	/**
	 * 构造函数
	 */
	public GxtComponentControllerMetaNodeModel (Map < String , Object > properties,int leftValue,int rightValue )
	{	
		super (
				properties ) ;
		if (leftValue<rightValue) {
			
			this.setLeftValue(leftValue);
			this.setRightValue(rightValue);
		} else {
			this.setLeftValue(1);
			this.setRightValue(2);
		}
		
	}
			
	public static Set<GxtAppEventType> addGxtAppEventType(String... appEventId){
		return addGxtAppEventType(new HashSet<GxtAppEventType>() , appEventId);
		
	}
	
	public static Set<GxtAppEventType> addGxtAppEventType(Set<GxtAppEventType> set,String... appEventId){
		//Set<GxtAppEventType> set =new HashSet<GxtAppEventType>();
		for (int i = 0; i < appEventId.length; i++) {
			
			set.add(new GxtAppEventType(appEventId[i]));
		}
		return set;
		
	}
	
	
	
	/*//@Transient
	@OneToMany(cascade={CascadeType.DETACH,CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH},fetch=FetchType.EAGER)
	@JoinColumn(name="GxtComponentMetaNodeModel_identifier")

	public Set<GxtAppEventType> getRegisterEventTypes() {
//		return super.get("registerEventTypes");
		return super.get(MetaDataConstants.APP_EVENT_TYPES);
	}

	public void setRegisterEventTypes(Set<GxtAppEventType> registerEventTypes) {
		super.set(MetaDataConstants.APP_EVENT_TYPES, registerEventTypes);
	}*/
	
	
	

}
